package ls.jpa.chapterC.domain;

import ls.jpa.chapterC.base.AudiTableEntity;
import org.apache.commons.lang.builder.ToStringBuilder;

import javax.persistence.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Barudisshu
 */
@Entity
@Table(name = "t_project", schema = "", catalog = "db_test")
@AttributeOverride(name = "id", column = @Column(name = "project_id", length = 32))
public class Project extends AudiTableEntity {

    @Basic
    @Column(name = "project_subject")
    private String projectSubject;

    @ManyToMany
    @JoinTable(name = "t_cp", joinColumns = @JoinColumn(name = "cp_cus_id",referencedColumnName = "project_id"),inverseJoinColumns = @JoinColumn(name = "cp_project_id",referencedColumnName = "cus_id"))
    private Collection<Customer> customers;

    @ManyToOne(cascade={CascadeType.ALL})
    @JoinColumn(name = "project_apd")
    private Project parentProject;

    @OneToMany(mappedBy = "parentProject")
    private Set<Project> projectApds = new HashSet<>();

    public String getProjectSubject() {
        return projectSubject;
    }

    public void setProjectSubject(String projectSubject) {
        this.projectSubject = projectSubject;
    }

    public Collection<Customer> getCustomers() {
        return customers;
    }

    public void setCustomers(Collection<Customer> customers) {
        this.customers = customers;
    }

    public Project getParentProject() {
        return parentProject;
    }

    public void setParentProject(Project parentProject) {
        this.parentProject = parentProject;
    }

    public Set<Project> getProjectApds() {
        return projectApds;
    }

    public void setProjectApds(Set<Project> projectApds) {
        this.projectApds = projectApds;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

}
